package cn.wolfcode.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;

@Setter
@Getter
public class Notice {
    public static final int EXIGENCY = 1; // 紧急
    public static final int IMPORTANT = 2; // 重要
    public static final int COMMON = 3; // 普通

    public static final int READ = 1; // 已读
    public static final int UNREAD = 0; // 未读

    public static final int ISSUE = 1; // 已发布
    public static final int UNPUBLISHED = 0; // 未发布

    public String getNoticeLevelDisplay() {
        switch (noticeLevel) {
            case EXIGENCY:
                return "紧急";
            case IMPORTANT:
                return "重要";
            case COMMON:
                return "普通";
            default:
                return "未知";
        }
    }

    public String getReadDisplay() {
        switch (haveRead) {
            case READ:
                return "已读";
            case UNREAD:
                return "未读";
            default:
                return "未知";
        }
    }

    public String getIssueStatusDisplay() {
        switch (issueStatus) {
            case ISSUE:
                return "已发布";
            case UNPUBLISHED:
                return "未发布";
            default:
                return "未知";
        }
    }


    /**
     * id
     */
    private Long id;
    /**
     * 公告标题
     */
    private String noticeTitle;
    /**
     * 公告内容
     */
    private String noticeContent;
    /**
     * 创建人
     */
    // private Long createId;
    private Employee creator;
    /**
     * 创建时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;
    /**
     * 公告等级
     */
    private int noticeLevel;
    /**
     * 是否已读
     */
    private int haveRead;
    /**
     * 发布状态
     */
    private int issueStatus;

    public String toJson() {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("noticeTitle", noticeTitle);
        map.put("noticeContent", noticeContent);
        map.put("noticeLevel", noticeLevel);
        map.put("xxx", getHaveRead());
        return JSON.toJSONString(map);
    }
}